package com.terry.test2.new2.impl;

import com.terry.test2.dp.Currency;
import com.terry.test2.dp.ExchangeRate;
import com.terry.test2.new2.ExchangeRateService;
import com.terry.test2.old.YahoolForexService;

import java.math.BigDecimal;

/**
 * @author 小八
 * @date 2023年02月01日17:37
 */
public class ExchangeRateServiceImpl implements ExchangeRateService {

    private YahoolForexService yahoolForexService;

    @Override
    public ExchangeRate getExchangeRate(Currency source, Currency target) {
        if(source.equals(target)){
            return new ExchangeRate(BigDecimal.ONE,source,target);
        }
        BigDecimal forex = yahoolForexService.getExchange(source.getCurrency(), target.getCurrency());
        return new ExchangeRate(forex,source,target);
    }

}
